

/** 页面管理器 */

import DropGoldItem_blxf from "../Common/dropGoldItem";
import IconNumItem_blxf from "../Common/iconNumItem";
import GameData_blxf from "../GameData/GameData";
import { VendorData_blxf } from "../GameData/VendorData";
import Guidance_blxf from "../GamePlayer/guidance";
import TipsPanel_blxf from "../GamePlayer/tipsPanel";
import AudioModule_blxf from "../Module/AudioModule";
import { ConfigModule_blxf } from "../Module/ConfigModule";
import { LoadModule_blxf } from "../Module/LoadModule";
import NodePool_blxf from "../Module/NodePool";
import PublicModule_blxf from "../Module/PublicModule";
import { UtilsModule_blxf } from "../Module/UtilsModule";
import AddShopAnimation_blxf from "../Panel/addShopAnimation";
import CommonVendorPanel_blxf from "../Panel/commonVendorPanel";
// import CoupletAnimationPanel_blxf from "../Panel/coupletAnimationPanel";
// import CoupletDragonLevel_blxf from "../Panel/coupletDragonLevel";
// import CoupletItem_blxf from "../Panel/coupletItem";
// import GuestBookPanel_blxf from "../Panel/guestBooksPanel";
// import NextPassPanel_blxf from "../Panel/nextPassPanel";
// import PassPanel_blxf from "../Panel/passPanel";
// import PathPanel_blxf from "../Panel/pathPanel";
// import RewaradPanel_blxf from "../Panel/rewardPanel";
// import VendorLvUpDetail_blxf from "../Panel/vendorLvUpDetail";
import { CsvManager_blxf } from "./CsvManager";
import { EnumManager_blxf } from "./EnumManager";

const {ccclass, property} = cc._decorator;

@ccclass
export default class PageManager_blxf {

    private constructor() { }

    private static _blxf_PageManager: PageManager_blxf = new PageManager_blxf();

    public static get instance (){
        return this._blxf_PageManager;
    }

    /** 加载页面队列 */
    private _loadListQueue: object[] = [];

    /** 已加载页面列表 */
    private _loadPageList: any[] = [];

    /** 弹窗父节点 */
    private _parentNode = null;
    /** 是否加载排队中 */
    private _isQueue: boolean = false;

    /**
     * 加载弹窗
     * @param data { pfName: 预制体名称，position: 坐标, parentNode: 父节点, zIndex: 层级, options: 传入参数, cb: 加载完成回调 } 
     */
    LoadPrefab_blxf ( data: object ) {
        let _cb: any = data['cb'];
        let _isPlay: boolean = data['isPlay'];
        let _pfName: string = data['pfName'];
        let _options: object = data['options'];

        if ( !_pfName ) return cc.warn('xtf_loadPrefab 参数错误 >>', data);

        let _zIndex: number = data['zIndex'] || 10;
        this._parentNode = cc.find('Canvas/game_panel');

        LoadModule_blxf.instance.LoadPrefab_blxf( [ _pfName ], ()=>{}, ( asserts: cc.Asset[] )=>{
            data['prefabNode'] = asserts[0];
            data['parentNode'] = data['parentNode'] || this._parentNode;
            if ( _isPlay ) data['parentNode'] = PublicModule_blxf.gamePlayParentNode;
            // cc.log('parentNode >>', data['parentNode']);
            let _newNode: cc.Node = LoadModule_blxf.instance.LoadNode_blxf( data );
            _newNode.zIndex = _zIndex;


            _cb && _cb( _newNode );

            if ( _newNode ) {
                this._loadPageList.push( { pfName: _pfName, node: _newNode, asserts } );
            }

            this.onCheckPanel_blxf( _pfName, _newNode );
        })
    }

    /** 检测预制体资源 */
    onCheckPageList_blxf () {
        this._loadPageList = this._loadPageList.filter( item =>{
            let { node, asserts } = item;
            let _isValid: boolean = cc.isValid( node );

            !_isValid && LoadModule_blxf.instance.onReleaseAssets_blxf( asserts );

            return _isValid;
        })
        // cc.log('this._loadPageList >>', this._loadPageList.length, this._loadPageList);
    }

    onOffAllPanel_blxf () {
        this._loadPageList.forEach( item =>{
            let { pfName, node } = item;
            let _pfData: any = CsvManager_blxf.instance.getPrefabData_blxf( pfName );
            if ( !_pfData ) return;

            let _isPanel: boolean = _pfData['IsPanel'] == 1;
            if ( !_isPanel ) return;

            node.destroy();
        })
    }

    /** 检测是否是弹窗 */
    onCheckPanel_blxf ( pfName: string, newNode: cc.Node ) {
        let _pfData: any = CsvManager_blxf.instance.getPrefabData_blxf( pfName );
        if ( !_pfData ) return;

        let _isPanel: boolean = _pfData['IsPanel'] == 1;
        if ( !_isPanel ) return;

        PublicModule_blxf.setOpenPanelNode_blxf( newNode );
    }

    /** 加载加载页 */
    loadLoadPage_blxf () {
        let _data: any = {
            pfName: EnumManager_blxf.prefabNameType.PREFAB_LOAD_PANEL
        }
        this.LoadPrefab_blxf( _data );
    }

    /** 加载引导 */
    loadGuidance_blxf ( type: number = 1 ) {
        let _isGui: boolean = GameData_blxf.instance.getIsGuidance_blxf();
        switch ( type ) {
            case 1 : _isGui = GameData_blxf.instance.getIsGuidance_blxf(); break;
            case 2 : _isGui = GameData_blxf.instance.getIsGuidanceAllShop_blxf(); break;
            case 3 : _isGui = GameData_blxf.instance.getIsGuidanceBuild_blxf(); break;
            case 4 : _isGui = GameData_blxf.instance.getIsGuidanceRoomBuild_blxf(); break;
        }
        if ( _isGui ) return;

        if ( PublicModule_blxf.isGui ) return;
        PublicModule_blxf.isGui = true;

        let _data: object = {
            zIndex: 100,
            pfName: EnumManager_blxf.prefabNameType.PREFAB_GUIDANCE,
            cb    : ( newNode: cc.Node ) =>{
                let _guidanceThis = newNode.getComponent( Guidance_blxf );
                _guidanceThis && _guidanceThis.initData_blxf( { type } )
            }
        }
        this.LoadPrefab_blxf( _data );
    }

    /** 加载叠叠乐引导 */
    loadGuidanceJenga_blxf () {
        let _isGuiJenga: boolean = GameData_blxf.instance.getIsGuidanceJenga_blxf();
        if ( _isGuiJenga ) return;

        if ( PublicModule_blxf.isGui ) return;
        PublicModule_blxf.isGui = true;

        let _data: object = {
            zIndex : 100,
            pfName : EnumManager_blxf.prefabNameType.PREFAB_GUIDANCE_JENGA,
            cb     : ( newNode: cc.Node ) =>{

            }
        }
        this.LoadPrefab_blxf( _data );
    }


    loadPageCallback_blxf () {
        if ( this._isQueue ) return;

        let _queueLen = this._loadListQueue.length;
        if ( _queueLen == 0 ) return;

        this._isQueue = true;
        let _data: any = this._loadListQueue[ 0 ];
        _data['_loadPageCallback_blxf'] = () =>{
            this._isQueue = false;
            this.loadPageCallback_blxf();
        }
        let { pageType } = _data;
        switch ( pageType ) {
            case 1 : this.loadNewGuestPanel_blxf( _data ); break;
            case 2 : this.loadNewShopPanel_blxf( _data ); break;
            default: break;
        }

        this._loadListQueue.splice(0, 1);
    }

    /** 加载队列页面 */
    loadQueuePage_blxf ( data: object ) {
        this._loadListQueue.push( data );

        this.loadPageCallback_blxf();
    }

    /**
     * 加载主玩法通用弹窗
     * @param options { type: 1空间不足、2库存不足、3老板别走、4老板留步、5温馨提示、6老板慎重 }
     */
    loadCommonVendorPanel_blxf ( options: any ) {
        let _data: object = {
            pfName : EnumManager_blxf.prefabNameType.PREFAB_COMMON_VENDOR_PANEL,
            cb      : ( newNode: cc.Node ) =>{
                newNode.getComponent(CommonVendorPanel_blxf).initData_blxf( options );
            }
        };
        this.LoadPrefab_blxf( _data );
    }

    /**
     * 加载游戏重置面板
     * @param options 
     */
    loadGameRestartPanel_blxf ( options: any ) {
        // // 弹窗检测
        // let _spaceRatio: number = VendorData_blxf.instance.getVendorAddShopMaxNum_blxf( true );
        // let _isCheck: boolean = _spaceRatio <= ConfigModule_blxf.spaceRatio;
        // if ( !_isCheck ) return;

        // let _data: object = {
        //     pfName : EnumManager_blxf.prefabNameType.PREFAB_GAME_RESTART_PANEL,
        //     cb     : ( newNode: cc.Node ) =>{
        //         newNode.getComponent(CommonVendorPanel_blxf).initData_blxf( options );
        //     }
        // };
        // this.LoadPrefab_blxf( _data );
    }

    /**
     * 加载新客人
     * @param options { guestName: 客人名字，path: 图集路径, imgName: 图片名 }
     */
    loadNewGuestPanel_blxf ( options: any ) {
        // let _data: object = {
        //     pfName : EnumManager_blxf.prefabNameType.PREFAB_NEW_GUEST_PANEL,
        //     cb      : ( newNode: cc.Node ) =>{
        //         newNode.getComponent(NewGuestPanel_blxf).initData_blxf( options );

        //         this.loadSpineCircleEffect_blxf( newNode, 0 )
        //         this.loadSpineColouredRibbon_blxf( newNode, 1 );
        //     }
        // };
        // this.LoadPrefab_blxf( _data );

        // // 新客人音效
        // AudioModule_blxf.instance.playAudio_blxf( EnumManager_blxf.gameAudioType.AUDIO_NEW );
    }


    /**
     * 加载新商品
     * @param options { shopName: 商品名字，path: 图集路径, imgName: 图片名, _loadPageCallback_blxf: 加载页回调 }
     */
    loadNewShopPanel_blxf ( options: any ) {
        // let _data: object = {
        //     pfName : EnumManager_blxf.prefabNameType.PREFAB_NEW_SHOP_PANEL,
        //     cb      : ( newNode: cc.Node ) =>{
        //         newNode.getComponent(NewShopPanel_blxf).initData_blxf( options );

        //         this.loadSpineColouredRibbon_blxf( newNode );
        //     }
        // };
        // this.LoadPrefab_blxf( _data );

        // // 随机背景音乐
        // AudioModule_blxf.instance.onRandomGameBgm_blxf();
        // // 新商品音效
        // AudioModule_blxf.instance.playAudio_blxf( EnumManager_blxf.gameAudioType.AUDIO_NEW );
    }

    /**
     * 加载财富榜
     */
    loadWealthPanel_blxf () {
        let _data: object = {
            pfName : EnumManager_blxf.prefabNameType.PREFAB_USE_WEALTH_PANEL,
            cb     : ( newNode: cc.Node ) =>{

            }
        }
        this.LoadPrefab_blxf( _data );
    }

    /**
     * 加载客源
     * @param options 
     */
    loadGuestBooksPanel_blxf ( options: any ) {
        // let _data: object = {
        //     pfName : EnumManager_blxf.prefabNameType.PREFAB_GUEST_BOOKS_PANEL,
        //     cb      : ( newNode: cc.Node ) =>{
        //         newNode.getComponent(GuestBookPanel_blxf).initData_blxf( options );
        //     }
        // };
        // this.LoadPrefab_blxf( _data );
    }

    /**
     * 加载客人信息
     * @param options { guestName: 商品名字，path: 图集路径, imgName: 图片名 }
     */
    loadGuestInfoPanel_blxf ( options: any ) {
        
        // let _data: object = {
        //     pfName : EnumManager_blxf.prefabNameType.PREFAB_GUEST_INFO_PANEL,
        //     cb      : ( newNode: cc.Node ) =>{
        //         newNode.getComponent(GuestInfoPanel_blxf).initData_blxf( options );
        //     }
        // };
        // this.LoadPrefab_blxf( _data );
    }

    /**
     * 加载商品信息
     * @param options { guestName: 商品名字，path: 图集路径, imgName: 图片名 }
     */
    loadShopInfoPanel_blxf ( options: any ) {
        // let _data: object = {
        //     pfName : EnumManager_blxf.prefabNameType.PREFAB_SHOP_INFO_PANEL,
        //     cb      : ( newNode: cc.Node ) =>{
        //         newNode.getComponent(GuestInfoPanel_blxf).initData_blxf( options );
        //     }
        // };
        // this.LoadPrefab_blxf( _data );
    }

    /** 加载进货榜 */
    loadShopRankPanel_blxf () {
        let _data: object = {
            pfName : EnumManager_blxf.prefabNameType.PREFAB_SHOP_RANK_PANEL 
        }
        this.LoadPrefab_blxf( _data );
    }

    /** 加载公益弹窗 */
    loadLovePanel_blxf ( options: any ) {
        // let _data: object = {
        //     pfName : EnumManager_blxf.prefabNameType.PREFAB_LOVE_PANEL,
        //     cb     : ( newNode: cc.Node ) =>{
        //         newNode.getComponent( LovePanel_blxf ).initData_blxf( options );
        //     }
        // }
        // this.LoadPrefab_blxf( _data );
    }

    /** 加载对联 */
    loadCoupletPanel_blxf () {
        let _data: object = {
            pfName : EnumManager_blxf.prefabNameType.PREFAB_COUPLET_PANEL 
        }
        this.LoadPrefab_blxf( _data );
    }

    /**
     * 加在彩带动画
     * @param parentNode 父节点
     * @param delayTime 延迟时间
     * @param cb 回调函数
     */
    loadSpineColouredRibbon_blxf ( parentNode: cc.Node, delayTime: number = 0, cb: any = ()=>{} ) {
        let { SPINE_UI_COLOURED_RIBBON } = EnumManager_blxf.gameSpineType;
        cc.tween( parentNode ).delay( delayTime ).call(()=>{
            UtilsModule_blxf.instance.createSpine_blxf( SPINE_UI_COLOURED_RIBBON, parentNode, cb );
        }).start();
    }

    /**
     * 加载客人光圈
     * @param parentNode 父节点
     * @param delayTime 延迟时间
     * @param cb 回调函数
     */
    loadSpineCircleEffect_blxf ( parentNode: cc.Node, delayTime: number = 0, cb: any = ()=>{} ) {
        let { SPINE_UI_CIRCLE_EFFECT } = EnumManager_blxf.gameSpineType;
        cc.tween( parentNode ).delay( delayTime ).call(()=>{
            UtilsModule_blxf.instance.createSpine_blxf( SPINE_UI_CIRCLE_EFFECT, parentNode, cb );
        }).start();
    }

    /**
     * 加载菜篮子解锁动画
     * @param parentNode 父节点
     * @param delayTime 延迟时间
     * @param cb 回调函数
     * @param targetLv 菜篮子等级
     */
    loadSpineTargetUnlock_blxf ( parentNode: cc.Node, delayTime: number = 0, cb: any = ()=>{}, targetLv: number ) {
        let { SPINE_GAME_TARGET_UNLOCK } = EnumManager_blxf.gameSpineType;
        UtilsModule_blxf.instance.createSpine_blxf( SPINE_GAME_TARGET_UNLOCK, parentNode, cb, `${targetLv}` );
    }

    /**
     * 加载菜篮子升级动画
     * @param parentNode 父节点
     * @param delayTime 延迟时间
     * @param cb 回调函数
     */
    loadSpineTargetLvUp_blxf ( parentNode: cc.Node, delayTime: number = 0, cb: any = ()=>{} ) {
        let { SPINE_GAME_TARGET_LEVELUP } = EnumManager_blxf.gameSpineType;
        UtilsModule_blxf.instance.createSpine_blxf( SPINE_GAME_TARGET_LEVELUP, parentNode, cb );
    }

    /**
     * 加载摊位解锁动画
     * @param parentNode 父节点
     * @param delayTime 延迟时间
     * @param cb 回调函数
     * @param targetLv 菜篮子等级
     */
    loadSpineVendorUnlock_blxf ( parentNode: cc.Node, delayTime: number = 0, cb: any = ()=>{} ) {
        return cb();

        let { SPINE_GAME_VENDOR_UNLOCK } = EnumManager_blxf.gameSpineType;
        UtilsModule_blxf.instance.createSpine_blxf( SPINE_GAME_VENDOR_UNLOCK, parentNode, cb );
    }

    loadSpineShopRemove_blxf ( parentNode: cc.Node, delayTime: number = 0, cb: any = ()=>{} ) {
        let { SPINE_GAME_SHOP_REMOVE } = EnumManager_blxf.gameSpineType;
        UtilsModule_blxf.instance.createSpine_blxf( SPINE_GAME_SHOP_REMOVE, parentNode, cb );
    }

    /**
     * 加载进度条火花
     * @param parentNode 父节点
     * @param delayTime 延迟时间
     * @param cb 回调函数
     */
    loadSpineProgressSpark_blxf ( parentNode: cc.Node, delayTime: number = 0, cb: any = ()=>{} ) {
        let { SPINE_UI_PROGRESS_SPARK } = EnumManager_blxf.gameSpineType;
        UtilsModule_blxf.instance.createSpine_blxf( SPINE_UI_PROGRESS_SPARK, parentNode, cb );
    }

    /**
     * 加载送货连击动画
     * @param animationName 连击数动画名
     */
    loadSpineCombo_blxf ( animationName: string = '2' ) {
        let { SPINE_GAME_COMBO } = EnumManager_blxf.gameSpineType;
        UtilsModule_blxf.instance.createSpine_blxf( SPINE_GAME_COMBO, null, null, animationName );
    }

    /**
     * 加载摊位集满动画
     * @param parentNode 父节点 
     * @param cb 回调函数
     */
    loadSpineVendorAll_blxf ( parentNode: cc.Node, cb: any ) {
        let { SPINE_GAME_VENDOR_ALL } = EnumManager_blxf.gameSpineType;
        UtilsModule_blxf.instance.createSpine_blxf( SPINE_GAME_VENDOR_ALL, parentNode, cb );
    }

    /**
     * 加载通用提示面板
     * @param options 
     */
    loadComonTipsPanel_blxf ( options: any ) {
        options['zIndex'] = options['zIndex'] || 999;
        let _data: object = {
            zIndex : options['zIndex'],
            pfName : EnumManager_blxf.prefabNameType.PREFAB_COMMON_TIPS_PANEL,
            cb     : ( newNode: cc.Node ) =>{
                newNode.getComponent(TipsPanel_blxf).initData_blxf( options );
            }
        };
        this.LoadPrefab_blxf( _data );
    }

    /**
     * 加载过关面板
     * @param options 
     */
    loadPassPanel_blxf ( options: any ) {
        // let _data: any = {
        //     pfName : EnumManager_blxf.prefabNameType.PREFAB_PASS_PANEL,
        //     cb     : ( newNode: cc.Node ) =>{
        //         newNode.getComponent(PassPanel_blxf).initData( options );

        //         this.loadSpinePassRibbon_blxf( newNode );

        //         OpenDataContext_blxf.showUserRankNum_blxf();
        //     }
        // };
        // this.LoadPrefab_blxf( _data );

        // AudioModule_blxf.instance.playAudio_blxf( EnumManager_blxf.gameAudioType.AUDIO_NEW );
    }
    
    /** 加载关卡彩带 */
    loadSpinePassRibbon_blxf ( parentNode: cc.Node, delayTime: number = 0, cb: any = ()=>{} ) {
        let { SPINE_UI_PASS_RIBBON } = EnumManager_blxf.gameSpineType;
        cc.tween( parentNode ).delay( delayTime ).call(()=>{
            UtilsModule_blxf.instance.createSpine_blxf( SPINE_UI_PASS_RIBBON, parentNode, cb );
        }).start();
    }

    /** 加载下关面板 */
    loadNextPassList_blxf ( options: any  ) {
        // let { PREFAB_NEXT_PASS_PANEL } = EnumManager_blxf.prefabNameType;
        // let _data: any = {
        //     zIndex : 200,
        //     pfName : PREFAB_NEXT_PASS_PANEL,
        //     cb     : ( newNode: cc.Node ) =>{
        //         let _nextPassPanelThis = newNode.getComponent(NextPassPanel_blxf)
        //         _nextPassPanelThis && _nextPassPanelThis.initData_blxf( options );

        //         let _cb = ( spineSkeleton: sp.Skeleton, duration: number )=>{
        //             cc.tween( newNode ).delay( duration - 0.1 )
        //             .call(()=>{
        //                 UtilsModule_blxf.instance.palyAnimation_blxf( spineSkeleton, { animationName: '1' })
        //             })
        //             .delay( 0.5 )
        //             .call(()=>{
        //                 newNode.destroy();

        //                 let { _closeCB } = options;
        //                 _closeCB && _closeCB();
        //             }).start();
        //         }
        //         let { SPINE_UI_NEXT_PASS } = EnumManager_blxf.gameSpineType;
        //         let _parentNode: cc.Node = _nextPassPanelThis.getPanleNode_blxf();
        //         UtilsModule_blxf.instance.createSpine_blxf( SPINE_UI_NEXT_PASS, _parentNode, _cb);
        //     }
        // }
        // this.LoadPrefab_blxf( _data );
    }

    /**
     * 加载对联获取字动画
     * @param options { coupletText: '福' }
     */
    loadCoupletAnimationPanel_blxf ( options: any ) {
        // let { PREFAB_COUPLET_ANIMATION } = EnumManager_blxf.prefabNameType;
        // let _data: any = {
        //     pfName : PREFAB_COUPLET_ANIMATION,
        //     cb     : ( newNode: cc.Node ) =>{
        //         let _coupletAnimationPanelThis = newNode.getComponent( CoupletAnimationPanel_blxf );
        //         _coupletAnimationPanelThis && _coupletAnimationPanelThis.initData_blxf( options );
        //     }
        // }
        // this.LoadPrefab_blxf( _data );
    }

    /** 加载主页对联和龙 */
    loadMainCoupletDragon_blxf ( options: any, cb: any ) {
        // let { PREFAB_COUPLET_DRAGON } = EnumManager_blxf.prefabNameType;
        // let _data: any = {
        //     pfName : PREFAB_COUPLET_DRAGON,
        //     cb     : ( newNode: cc.Node ) =>{
        //         let _coupletItemThis = newNode.getComponent( CoupletItem_blxf );
        //         _coupletItemThis && _coupletItemThis.initData_blxf( options );

        //         cb && cb( newNode );
        //     }
        // }
        // this.LoadPrefab_blxf( _data );
    }

    /** 加载龙等级 */
    loadDragonLvPanel_blxf ( options ) {
        // let { PREFAB_DRAGON_LV } = EnumManager_blxf.prefabNameType;
        // let _data: any = {
        //     pfName : PREFAB_DRAGON_LV,
        //     cb     : ( newNode: cc.Node ) =>{
        //         let _this = newNode.getComponent( CoupletDragonLevel_blxf );
        //         _this && _this.initData_blxf( options );
        //     }
        // }
        // this.LoadPrefab_blxf( _data );
    }

    /** 加载摊位升级选择面板 */
    loadVendorLvUpPanel_blxf () {
        let { PREFAB_VENDOR_LVUP_PANEL } = EnumManager_blxf.prefabNameType;
        let _data: any = {
            pfName: PREFAB_VENDOR_LVUP_PANEL
        }
        this.LoadPrefab_blxf( _data );
    }

    /** 加载摊位升级详情界面 */
    loadVendorLvUpDetail_blxf ( options: any ) {
        // let { PREFAB_VENDOR_LVUP_DETAIL } = EnumManager_blxf.prefabNameType;
        // let _data: any = {
        //     pfName: PREFAB_VENDOR_LVUP_DETAIL,
        //     cb    : ( newNode: cc.Node ) =>{
        //         let _this = newNode.getComponent( VendorLvUpDetail_blxf );
        //         _this && _this.inintData_blxf( options );
        //     }
        // }
        // this.LoadPrefab_blxf( _data );
    }

    /** 加载上货动画 */
    loadAddShopAnimation_blxf ( options: any ) {
        let { PREFAB_ADD_SHOP_ANIMATION } = EnumManager_blxf.prefabNameType;
        let _data: any = {
            pfName: PREFAB_ADD_SHOP_ANIMATION,
            cb    : ( newNode: cc.Node ) =>{
                let _this = newNode.getComponent( AddShopAnimation_blxf );
                _this && _this.initData_blxf( options );
            }
        }
        this.LoadPrefab_blxf( _data );
    }

    /** 查看库存 */
    loadLookPanel_blxf () {
        let { PREFAB_ADD_SHOP_PANEL } = EnumManager_blxf.prefabNameType;
        let _data: any = {
            pfName: PREFAB_ADD_SHOP_PANEL
        }
        this.LoadPrefab_blxf( _data );
    }

    /** 升级 */
    loadLevelUpPanel_blxf () {
        let { PREFAB_LEVEL_UP_PANEL } = EnumManager_blxf.prefabNameType;
        this.LoadPrefab_blxf({
            pfName: PREFAB_LEVEL_UP_PANEL
        })
    }

    /** 掉落金币 */
    loadDropGoldItem_blxf ( position: cc.Vec3, parentNode: cc.Node, options: any ) {
        let { PREFAB_DROP_GOLD_ITEM } = EnumManager_blxf.prefabNameType;
        this.LoadPrefab_blxf({
            position, parentNode,
            pfName : PREFAB_DROP_GOLD_ITEM,
            cb     : ( newNode: cc.Node ) =>{
                let _this = newNode.getComponent( DropGoldItem_blxf );
                _this && _this.initData_blxf && _this.initData_blxf( options );

                UtilsModule_blxf.instance.setNodeZIndex_blxf( newNode, -1 );
            }
        })
    }

    /** 加载奖励弹窗 */
    loadRewardPanel_blxf ( options: any ) {
        // let { PREFAB_REWARD_PANEL } = EnumManager_blxf.prefabNameType;
        // this.LoadPrefab_blxf({
        //     pfName : PREFAB_REWARD_PANEL,
        //     cb     : ( rewardPanel: cc.Node ) =>{
        //         let _rewardPanelThis = rewardPanel.getComponent( RewaradPanel_blxf );
        //         _rewardPanelThis && _rewardPanelThis.initData_blxf && _rewardPanelThis.initData_blxf( options );
        //     }
        // })
    }

    /** 加载游戏选择按钮列表 */
    loadGameChooseBtnList_blxf ( data: any ) {
        let { PREFAB_GAME_CHOOSE_BTN } = EnumManager_blxf.prefabNameType;
        this.LoadPrefab_blxf({
            pfName : PREFAB_GAME_CHOOSE_BTN,
            cb     : ( newNode: cc.Node ) =>{

            }
        })
    }

    /** 加载叠叠乐玩法页 */
    loadGamePlayPage_blxf ( cb: any= ()=>{} ) {
        if ( PublicModule_blxf.pageNodeInfo[ '4' ] ) return;
        let { PREFAB_GAME_PLAY_PAGE } = EnumManager_blxf.prefabNameType;
        this.LoadPrefab_blxf({
            pfName : PREFAB_GAME_PLAY_PAGE,
            cb     : ( newNode: cc.Node ) =>{
                PublicModule_blxf.pageNodeInfo[ '4' ] = newNode;
                cb && cb();
            }
        })
    }

    /** 加载食堂菜谱 */
    loadFoodPanel_blxf ( data: any = null ) {
        let { PREFAB_FOOD_PANE } = EnumManager_blxf.prefabNameType;
        this.LoadPrefab_blxf({
            pfName : PREFAB_FOOD_PANE,
            cb     : ( newNode: cc.Node ) =>{

            }
        })
    }

    /** 加载解锁食堂弹窗 */
    loadUnlockKitchenPanel_blxf ( data: any = null ) {
        let { PREFAB_UNLOCK_KITCHEN_PANEL } = EnumManager_blxf.prefabNameType;
        this.LoadPrefab_blxf({
            pfName : PREFAB_UNLOCK_KITCHEN_PANEL,
            cb     : ( newNode: cc.Node ) =>{

            }
        })
    }

    /** 加载货币途径弹窗 */
    loadPathPanel_blxf ( data: any = null ) {
        // let { PREFAB_PATH_PANEL } = EnumManager_blxf.prefabNameType;
        // this.LoadPrefab_blxf({
        //     pfName : PREFAB_PATH_PANEL,
        //     cb     : ( newNode: cc.Node ) =>{
        //         let _this = newNode.getComponent( PathPanel_blxf );
        //         _this && _this.initData_blxf( data );
        //     }
        // })
    }

    /** 加载厨房内装饰 */
    loadKitchenPanel_blxf ( data: any = null ) {
        if ( PublicModule_blxf.pageNodeInfo[ '5' ] ) return;

        let _data = {
            zIndex     : 9,
            pfName     : EnumManager_blxf.prefabNameType.PREFAB_KITCHEN_PANEL,
            parentNode : data.parentNode,
            cb         : ( newNode: cc.Node ) =>{
                PublicModule_blxf.pageNodeInfo[ '5' ] = newNode;
            }
        }
        PageManager_blxf.instance.LoadPrefab_blxf( _data );
    }

    /** 加载设置面板 */
    loadSetPanel_ddlxc () {
        let { PREFAB_SET_PANEL } = EnumManager_blxf.prefabNameType;
        this.LoadPrefab_blxf({
            pfName: PREFAB_SET_PANEL
        });
    }

    /**
     * 默认传个起点
     * inP：起点，
     * toP：终点，
     * count：数量，
     * goldCoin：金币总数
     * name: 预制体名称
     * @param options 
     */
    onIconAnimation_blxf ( type: number, iconNum: number, inP: cc.Vec3, toP: cc.Vec3 = null, parentNode: cc.Node = null ) {  
        let getR = ( n: number ) => { return Math.floor(Math.random() * n) };

        let _isDef: boolean = type == -1;
        let _inP: cc.Vec3 = inP || cc.v3(); 
        let _toP = null, _baseIconNum = 0, _pfName: string, _audioId: string, _numStr: string;
        let _isAutoPage: boolean = PublicModule_blxf.gamePlayPageId == 2;
        let _isMainPlay: boolean = PublicModule_blxf.gamePlayPageId == 1;
        let { NUM_GOLD, NUM_DIAMOND, NUM_PAPER } = EnumManager_blxf.gameNumType;
        switch ( type ) {
            case NUM_GOLD : _baseIconNum = 10, _toP = !_isMainPlay ? PublicModule_blxf.autoGoldIconPos : PublicModule_blxf.goldIconPos; 
                _pfName = EnumManager_blxf.prefabNameType.PREFAB_GOLD_ITEM;
                _audioId = EnumManager_blxf.gameAudioType.AUDIO_GOLD;
                _numStr = `到账+${iconNum}`;
                break;
            case NUM_DIAMOND : _baseIconNum =  5, _toP = !_isMainPlay ? PublicModule_blxf.autoDiamondIconPos :PublicModule_blxf.diamondIconPos;
                _pfName = EnumManager_blxf.prefabNameType.PREFAB_DIAMOND_ITEM;
                _audioId = EnumManager_blxf.gameAudioType.AUDIO_DIAMOND;
                _numStr = `财富+${iconNum}`;
                break;
            case NUM_PAPER : _baseIconNum = 5, _toP = PublicModule_blxf.autoPaperIconPos;
                _pfName = EnumManager_blxf.prefabNameType.PREFAB_PAPER_ITEM;
                _audioId = EnumManager_blxf.gameAudioType.AUDIO_GOLD;
                break;
            default: _baseIconNum = 1; _toP = toP;
                _pfName = EnumManager_blxf.prefabNameType.PREFAB_GOLD_ITEM;
                // _audioId = EnumManager_blxf.gameAudioType.AUDIO_GOLD;
                break;
        }
        if ( !_toP ) return;

        let { x, y } = _toP;

        let _n = Math.round( iconNum / _baseIconNum );
        let _iconNum = _n < 3 ? 3 : _n;
        if ( _isDef ) _iconNum = _n;
        if ( _iconNum > 10 ) _iconNum = 10;
        let _byTime: number = 0.6, _toTime: number = 1;

        let _randomN = _isDef ? 80 : 120;
        for ( let i = 0; i < _iconNum; i++ ) {
            let _iconNode = LoadModule_blxf.instance.LoadNode_blxf({
                prefabNode: NodePool_blxf.get( _pfName ),
                parentNode, position : _inP,
                zIndex: _isDef ? 9 : 1999
            })
            // this.LoadPrefab_blxf({ pfName: _pfName, position: _inP, zIndex: 1999, cb: ( _iconNode )=>{
                let num1 = getR(_randomN * 2) - _randomN;
                let num2 = getR(_randomN * 2) - _randomN;
                let num3 = getR(200) / 1000;
                cc.tween(_iconNode)
                    .delay(num3)
                    .by( _byTime, {x: num1, y: num2}, cc.easeSineOut() )
                    .to( _toTime, {x, y}/*, cc.easeSineInOut()*/)
                    .call(()=>{
                        if(i != 0) return _iconNode.destroy();
                        
                        _audioId && AudioModule_blxf.instance.playAudio_blxf( _audioId );
                        !_isDef && cc.game.emit('onUpdateTopNum_blxf');
                        // // 货币数动画
                        // this.onIconNumAnimation_blxf( _numStr, _toP );

                        // _iconNode.destroy();
                        NodePool_blxf.put( _pfName, _iconNode );
                    })
                    .start();
            // }});
        }
    }

    /**
     * 货币数动画
     * @param num 货币数
     * @param endPos 显示坐标
     */
    onIconNumAnimation_blxf ( num: any, endPos: cc.Vec3, num2: any = undefined ) {
        let _nodePos = endPos/*.add( cc.v3(40, 30) )*/;
        let { PREFAB_ICON_NUM_ITEM } = EnumManager_blxf.prefabNameType; 
        // this.LoadPrefab_blxf({
        //     pfName   : PREFAB_ICON_NUM_ITEM,
        //     position : _nodePos, zIndex: 2999,
        //     cb       : ( numNode: cc.Node ) =>{
        //         numNode.getComponent(IconNumItem_blxf).initData_blxf({ num, num2 });
        //     }
        // })

        let _numNode = LoadModule_blxf.instance.LoadNode_blxf({
            prefabNode: NodePool_blxf.get( PREFAB_ICON_NUM_ITEM ),
            position  : _nodePos, zIndex: 2999,
        })
        _numNode.getComponent(IconNumItem_blxf).initData_blxf({ num, num2 });
    }
}
